package com.springboot.controller;

import com.springboot.beans.HttpResponseEntity;
import com.springboot.common.Constans;
import com.springboot.dao.entity.Modeule_name;
import com.springboot.dao.entity.UserEntity;
import com.springboot.dao.entity.User_branch;
import com.springboot.dao.entity.User_module;
import com.springboot.service.UserService;
import org.apache.ibatis.ognl.IntHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018\9\8 0008.
 */
@RestController
public class UserController {



    @Autowired
    private UserService userService;

    /**
     * 添加用户信息
     * @param userEntity
     * @return
     */
    @RequestMapping(value = "/addUserInfo",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity getSendInfo(@RequestBody UserEntity userEntity) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            int result = userService.addUserInfo(userEntity);
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(result);

        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据用户id查询用户信息
     * @param map
     * @return
     */
    @RequestMapping(value = "/queryUserInfo",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity queryUserInfo(@RequestBody Map<String,Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            UserEntity result = userService.queryUserInfo(map);
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(result);

        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 后台管理左侧下拉菜单
     * @param map
     * @return
     */
    @RequestMapping(value = "/back_stage_management",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity back_stage_management(@RequestBody Map<String,Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
          Object object=  userService.back_management(map);
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(object);
        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }


    /**
     * 所有模块的文字显示
     * @param
     * @return
     */
    @RequestMapping(value = "/set_up_all",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity set_up_all() {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            List<Modeule_name> modeule_name = userService.set_up_all();
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(modeule_name);

        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }
    /**
     * 设置根据用户选择的模块个数修改数据
     * @param map
     * @return
     */
    @RequestMapping(value = "/Update_module_data",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity Update_module_data(@RequestBody  Map<String,Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            int result = userService.Update_module_data(map);
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(result);

        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }


    /**
     * 设置,用户选择单选框的存在状态
     * @param
     * @return
     */
    @RequestMapping(value = "/module_state_data",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity module_state_data(@RequestBody  Map<String,Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            List result = userService.module_state_data(map);
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(result);

        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }


    /**
     * 根据用户id修改用户信息
     * @param userEntity
     * @return
     */
    @RequestMapping(value = "/modifyUserInfo",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity modifyUserInfo(@RequestBody UserEntity userEntity) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            int result = userService.modifyUserInfo(userEntity);
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(result);

        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }

    /**
     * 根据用户id删除用户信息
     * @param map
     * @return
     */
    @RequestMapping(value = "/deleteUserInfo",method = RequestMethod.POST, headers = "Accept=application/json")
    public HttpResponseEntity deleteUserInfo(@RequestBody Map<String,Object> map) {
        HttpResponseEntity httpResponseEntity = new HttpResponseEntity();
        try {
            int result = userService.deleteUserInfo(map);
            httpResponseEntity.setCode(Constans.SUCCESS_CODE);
            httpResponseEntity.setData(result);

        } catch (Exception e) {
            httpResponseEntity.setCode(Constans.ADD_EXIST_CODE);
            httpResponseEntity.setMessage(Constans.ADD_EXIST_MESSAGE);
        }
        return httpResponseEntity;
    }


}
